<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/8/8
 * Time: 10:46
 */
class CountWeightController
{
    private $CWService;

    function __construct()
    {
        $this->CWService          =   new CountWeightService();
    }

    public function testCW()
    {
        $this->CWService->testAmq();
    }

    public function addCountWeight($param)
    {
    	$type = trim($param['type']);
    	$type_id = intval($param['type_id']);
    	$data = json_decode($param['data'], true);

    	if (empty($type) || empty($type_id) || empty($data))
    	{
    		return false;
    	}

        $result      = 0;
        $CWService   = new CountWeightService($type, $type_id);
    	$countWeight = $CWService->getCountWeight();
    	if (empty($countWeight))
    	{
    		$result = $CWService->initCountWeight($data);
    	}

    	if (empty($result) && $countWeight)
    	{
    		$result = $CWService->editCountWeight($data);
    	}

    	return $result ? true : false;
    }
}